#ifndef WHEEL_MOTOR_SOCKETCAN_HPP
#define WHEEL_MOTOR_SOCKETCAN_HPP

#include <chrono>
#include <memory>
#include <string>


#include <iostream>
#include <cstring>
#include <unistd.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <net/if.h>
#include <linux/can.h>
#include <linux/can/raw.h>

namespace wheel_motor_hardware_interface
{
class wheel_motor_socketcan
{
private:
    int socket_fd_;
    struct sockaddr_can addr_;
    struct ifreq ifr_;

    u_int32_t wheel_motor_id_{0x141U}; // 轮毂电机canid
    double reduction_ratio_{6.0}; // 电机减速比
public:
    wheel_motor_socketcan();
    ~wheel_motor_socketcan();
    // 初始化socketcan通信
    bool init(const char* ifname);
    // 电机运行
    bool wheel_motor_start();
    // 电机关闭
    bool wheel_motor_shutdown();
    // 转矩闭环控制命令(输入扭矩单位N*m)
    void wheel_motor_effort_control(double effort);
    // 速度闭环控制命令(输入速度单位rad/s)
    void wheel_motor_velocity_control(double velocity);
    // 读取电机多圈角度绝对值(0.01度/LSB), 返回值为rad
    double wheel_motor_angle_read();
    // 读取电机速度(1dps/LSB), 返回值为rad/s
    double wheel_motor_velocity_read();

};

}



#endif